package com.itheima.sort;

import java.awt.print.Printable;

public class BubbleSort {
    public static void main(String[] args) {
        int[] arr = {3,1,5,2,4};

        //1.外层循环表示轮数
        for (int i = 0; i < arr.length-1; i++) {
        //内层循环表示每轮循环比较的次数
            for (int j = 0; j < arr.length-1-i; j++) {
                if(arr[j]>arr[j+1]){
                    int temp =arr[j];
                    arr[j] =arr[j+1];
                    arr[j+1] =temp;
                }
            }
        }
        Print(arr);
    }

    private static void Print(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }
    }
}
